package com.mc.moring.netconfig

import com.mc.moring.util.HttpsUtil
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 * <pre>
 *     author : HevenHolt
 *     e-mail : hyt0302@qq.com
 *     time   : 2023/11/29
 *     desc   :
 *     version: 1.0
 * </pre>
 */
object HeadApi {
    private val retrofit: Retrofit = Retrofit.Builder().apply {
        baseUrl("https://backend.moni-cash.com/remote/")
        client(newOkHttpClient())
        addConverterFactory(GsonConverterFactory.create())
    }.build()

    fun <T> create(clazz: Class<T>): T = retrofit.create(clazz)

    private fun newOkHttpClient(): OkHttpClient = OkHttpClient.Builder().apply {
        addInterceptor(HttpLoggingInterceptor().apply {
            setLevel(HttpLoggingInterceptor.Level.BODY)
        })
        addInterceptor(HeadtInterceptor())
        HttpsUtil.getSSLSocketFactory()
        HttpsUtil.getHostnameVerifier()
    }.build()

}